<template>
  <div class="feedbackPage">
    <el-form :inline="true" style="padding: 25px 10px">
      <el-form-item>
        <Upload
          :limit="1"
          state="7"
          listType="text"
          :showFileList="false"
          customAction="/house/api/image/uploadSlideshowFile"
          @onSuccess="onSuccess"
        >
          <template>
            <el-button type="primary" size="medium">添加</el-button>
          </template>
        </Upload>
      </el-form-item>
    </el-form>

    <el-table v-loading="listLoading" :data="pagelist" element-loading-text="正在加载...">
      <el-table-column label="创建时间">
        <template #default="{ row }">
          {{ row.createTime.split('T')[0] }}
        </template>
      </el-table-column>
      <el-table-column label="图片" prop="opinion">
        <template #default="{ row }">
          <el-image style="width: 100px; height: 100px" :preview-src-list="[row.imagePath]" :src="row.imagePath" />
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template #default="{ row }">
          <el-button type="danger" @click="handleDelete(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNo"
      layout="total, sizes, prev, pager, next, jumper"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
  </div>
</template>

<script>
  import request from '@/utils/request'
  import Upload from '@/components/Upload.vue'
  import { doDelete } from '@/api/house/image'
  export default {
    name: 'RoomManagement',
    components: {
      Upload,
    },
    data() {
      return {
        pagelist: [],
        listLoading: true,
        total: 0,
        queryForm: {
          pageNo: 1,
          pageSize: 10,
        },
      }
    },
    created() {
      this.fetchData()
    },

    methods: {
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNo = val
        this.fetchData()
      },

      // 获取数据
      async fetchData() {
        try {
          this.listLoading = true
          const { data } = await request({
            url: '/house/api/image/findSlideshowFile',
            method: 'get',
            params: this.queryForm,
          })
          this.pagelist = data.list
          this.total = data.totalCount
          this.listLoading = false
        } catch (error) {
          this.listLoading = false
        }
      },

      // 上传成功
      onSuccess() {
        console.info('12312321  ----->  ', 12312321);
        this.fetchData()
      },

      // 删除
      handleDelete(row) {
        this.$baseConfirm('你确定要删除当前项吗', null, async () => {
          try {
            await doDelete(row.id)
            this.fetchData()
            this.$baseMessage('删除成功', 'success')
          } catch (error) {
            console.info('error  ----->  ', error)
          }
        })
      },
    },
  }
</script>

<style lang="scss" scoped></style>
